<template>
  <div>
    <el-breadcrumb separator="/" style="margin-bottom: 20px;">
      <el-breadcrumb-item :to="{ path: '/' }">投资管理</el-breadcrumb-item>
      <el-breadcrumb-item>投资历史</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="block">
      <el-timeline>
        <el-timeline-item
          v-for="item in investData"
          :key="item._id"
          :timestamp="'投资单号：' + item._id"
          placement="top"
        >
          <el-card>
            <el-button
              style="position: absolute; right: 2vw;"
              type="danger"
              icon="el-icon-delete"
              circle
              @click="delClick(item)"
            ></el-button>
            <h4>{{ item.models }}</h4>
            <p>投资金额： {{ item.cash }}元</p>
            <p>投资时间： {{ item.createTime | timeFilter }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      investForm: {},
      investData: []
    };
  },
  mounted() {
    this.getList();
  },
  computed: {
    ...mapState(["carModel", "userInfo"])
  },
  methods: {
    getList() {
      this.investForm.number = this.userInfo.number;
      this.$api
        .get("/api/invest/list/all", { params: this.investForm })
        .then(res => {
          console.log(res.data.data);
          this.investData = res.data.data;
        })
        .catch(err => {
          console.log(err);
          this.$message.error("获取列表失败");
        });
    },
    delClick(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$api
            .delete(`/api/invest/delete/${row._id}`)
            .then(res => {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.pageNum = 1;
              this.getList();
            })
            .catch(err => {
              this.$message({
                type: "error",
                message: "删除失败"
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>

<style></style>
